//
//  InfoAllViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/7/17.
//

#import "InfoAllViewController.h"
#import <TTRangeSlider/TTRangeSlider.h>
#import <BRPickerView/BRPickerView.h>
//#import "InfoMapViewController.h"
#import "TiZhongPopView.h"
#import "ShengGaoPopView.h"
#import "RealViewController.h"
#import "ViewController.h"
@interface InfoAllViewController ()<UITextFieldDelegate>
@property (nonatomic , strong) UILabel * shengaoLabel;
@property (nonatomic , strong) UILabel * tizhongLabel;
@property (nonatomic , strong) UILabel * addressLabel;
@property (nonatomic , strong) UILabel * shengriLabel;
@property (nonatomic , strong) UITextField * textField;
@end

@implementation InfoAllViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.blackColor;
    self.zx_navLeftBtn.hidden = YES;
    WS(weakSelf);
    if ([[UserModel share].userid isEqualToString:@"125"]) {
        [self zx_setRightBtnWithText:SQNSLocalString(@"跳过") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
            
            [weakSelf SQ_popVCType];
        }];
    }else{
        
        NSString * valuue = [Manager SQ_stringForKey:@"userinfo_switch"];
        if (![valuue isEqualToString:@"1"]) {
            return;
        }
        
        [self zx_setRightBtnWithText:SQNSLocalString(@"跳过") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
            
            [weakSelf SQ_popVCType];
        }];
    }
}

- (void)SQ_UIViewForSelfView{
    
    for (int x = 0; x<3; x++) {
        UIView * bglineview = [[UIView alloc]init];
        bglineview.backgroundColor = SQColor(@"#BF33FF");
        [self.view addSubview:bglineview];
        [bglineview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(SCREEN_WIDETH/3.f-4);
            make.height.mas_equalTo(2);
            make.left.equalTo(self.view).offset(SCREEN_WIDETH/3.f*x);
            make.bottom.equalTo(self.zx_navBar.mas_bottom);
        }];
    }
    
    UILabel * num = [[UILabel alloc]init];
    num.text = SQNSLocalString(@"3/3");
    num.font = FONT_MEDIUM(13);
    num.textColor = SQColor(@"#6B6B6B");
    [self.view addSubview:num];
    [num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-24);
        make.top.equalTo(self.zx_navBar.mas_bottom).offset(8);
    }];
    
    UIImageView * topImage = [[UIImageView alloc]init];
    topImage.image = SQGetImage(@"椭圆形");
    topImage.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:topImage];
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(12);
        make.top.equalTo(self.zx_navBar.mas_bottom).offset(10);
        make.size.mas_equalTo(68);
    }];
    UILabel * label1 = [[UILabel alloc]init];
    label1.text = SQNSLocalString(@"你好~");
    label1.textColor = UIColor.whiteColor;
    label1.font = FONT_NIHAO(32);
    [self.view addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(35);
        make.top.equalTo(self.zx_navBar.mas_bottom).offset(25);
        
    }];
    
    UILabel * num2 = [[UILabel alloc]init];
    num2.text = SQNSLocalString(@"完善一下资料吧");
    num2.font = FONT_SEMIBOLD(18);
    num2.textColor = UIColor.whiteColor;
    [self.view addSubview:num2];
    [num2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(35);
        make.top.equalTo(label1.mas_bottom).offset(8);
    }];
    
    UIImageView * bgImage = [[UIImageView alloc]init];
    bgImage.image = SQGetImage(@"infoAllBg");
    [self.view addSubview:bgImage];
    [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.top.equalTo(num2.mas_bottom).offset(17);
            make.height.mas_equalTo(54);
            make.width.mas_equalTo(SCREEN_WIDETH-54);
    }];
    
    UILabel * num3 = [[UILabel alloc]init];
    num3.text = SQNSLocalString(@"完善你的个人详情资料，可以获得更多曝光，");
    num3.font = FONT_MEDIUM(12);
    num3.numberOfLines = 0;
    num3.textAlignment = NSTextAlignmentCenter;
    num3.textColor = SQColor(@"#945B28");
    [self.view addSubview:num3];
    [num3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(bgImage);
        make.width.mas_equalTo(SCREEN_WIDETH-154);
    }];
    
    UILabel * num4 = [[UILabel alloc]init];
    num4.text = SQNSLocalString(@"基本资料");
    num4.font = FONT_MEDIUM(17);
    num4.textColor = UIColor.whiteColor;
    [self.view addSubview:num4];
    [num4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(35);
        make.top.equalTo(bgImage.mas_bottom).offset(18);
    }];
    NSArray * array = @[@"生日",@"常驻地",@"身高",@"体重"];
    for (int x = 0; x< array.count; x++) {
        UIView * bg = [[UIView alloc]init];
        bg.backgroundColor = SQColor(@"#414141");
        bg.layer.cornerRadius = 8;
        bg.layer.masksToBounds = YES;
        [self.view addSubview:bg];
        [bg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(num4.mas_bottom).offset(x*(12+44)+12);
            make.height.mas_equalTo(44);
            make.centerX.equalTo(self.view);
            make.width.mas_equalTo(SCREEN_WIDETH-54);
        }];
        UILabel * num5 = [[UILabel alloc]init];
        num5.text = SQNSLocalString([array objectAtIndex:x]);
        num5.font = FONT_MEDIUM(14);
        num5.textColor = SQColor(@"#6B6B6B");
        [bg addSubview:num5];
        [num5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bg).offset(16);
            make.centerY.equalTo(bg);
        }];
        if (x == 0) {
            [bg addSubview:self.shengriLabel];
            [self.shengriLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(bg.mas_right).offset(-16);
                make.centerY.equalTo(bg);
            }];
        } else  if (x == 1) {
            [bg addSubview:self.addressLabel];
            [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(bg.mas_right).offset(-16);
                make.centerY.equalTo(bg);
            }];
        }else  if (x == 2) {
            [bg addSubview:self.shengaoLabel];
            [self.shengaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(bg.mas_right).offset(-16);
                make.centerY.equalTo(bg);
            }];
        }else  if (x == 3) {
            [bg addSubview:self.tizhongLabel];
            [self.tizhongLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(bg.mas_right).offset(-16);
                make.centerY.equalTo(bg);
            }];
        }
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 1000+x;
        btn.backgroundColor = UIColor.clearColor;
        [btn addTarget:self action:@selector(SQ_ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [bg addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(bg);
        }];
    }
    UILabel * num5 = [[UILabel alloc]init];
    num5.text = SQNSLocalString(@"微信号");
    num5.font = FONT_MEDIUM(17);
    num5.textColor = UIColor.whiteColor;
    [self.view addSubview:num5];
    [num5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(35);
        make.top.equalTo(num4.mas_bottom).offset(256);
    }];
    [self.view addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.top.equalTo(num5.mas_bottom).offset(16);
            make.width.mas_equalTo(SCREEN_WIDETH-70);
            make.height.mas_equalTo(44);
    }];
    UIImageView * leftImage = [[UIImageView alloc]init];
    leftImage.image = SQGetImage(@"vxx");
    [self.textField addSubview:leftImage];
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(24);
            make.centerY.equalTo(self.textField);
            make.left.equalTo(self.textField).offset(16);
    }];
    
    UILabel * num6 = [[UILabel alloc]init];
    num6.text = SQNSLocalString(@"只有VIP用户能看到哟");
    num6.font = FONT_MEDIUM(12);
    num6.textColor = SQColor(@"#C79B58");
    [self.view addSubview:num6];
    [num6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.textField);
        make.top.equalTo(self.textField.mas_bottom).offset(6);
    }];
    
    HeaderView * xiayibu = [[HeaderView alloc]init];
    xiayibu.image = @"下一步";
    [xiayibu.btn addTarget:self action:@selector(SQ_tijiaoButton) forControlEvents:UIControlEventTouchUpInside];
    xiayibu.font = FONT_MEDIUM(18);
    [self.view addSubview:xiayibu];
    [xiayibu mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(72);
        make.top.equalTo(num6.mas_bottom).offset(20);
    }];
    
    if ([SKStoreReviewController respondsToSelector:@selector(requestReviewInScene:)]) {
        NSArray *array =[[[UIApplication sharedApplication] connectedScenes] allObjects];
        UIWindowScene *windowScene = (UIWindowScene *)array[0];
        [SKStoreReviewController requestReviewInScene:windowScene];
    }
}

-(void)SQ_tijiaoButton{
    if ([self.shengriLabel.text isEqualToString:@"待完善"]) {
        [YJProgressHUD showMsgWithoutView:@"请选择生日"];
        return;
    }
    
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    if ([self.shengaoLabel.text isNotEmpty]&&![self.shengaoLabel.text isEqualToString:@"待完善"]) {
        [dic setObject:[self.shengaoLabel.text stringByReplacingOccurrencesOfString:@"CM" withString:@""] forKey:@"height"];
    }
    if ([self.tizhongLabel.text isNotEmpty]&&![self.tizhongLabel.text isEqualToString:@"待完善"]) {
        [dic setObject:[self.tizhongLabel.text stringByReplacingOccurrencesOfString:@"KG" withString:@""] forKey:@"weight"];
    }
    [dic setObject:self.shengriLabel.text forKey:@"birthday"];
    if ([self.addressLabel.text isNotEmpty]) {
        [dic setObject:self.addressLabel.text forKey:@"address"];
    }
    if ([self.textField.text isNotEmpty]) {
        [dic setObject:self.textField.text forKey:@"wx"];
    }
    [HttpTool post:Url5 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [self SQ_popVCType];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
    
}

-(void)SQ_popVCType{
    WS(weakSelf);
    UserModel * model = [UserModel share];
    if (model.gender == 1) {
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc]init] ];
        weakSelf.view.window.rootViewController = nav;
    } else {
        RealViewController * vc = [[RealViewController alloc]init];
        vc.isInfo = YES;
        [weakSelf SQ_pushViewControllerFull:vc];
    }
}

-(void)SQ_ButtonClick:(UIButton*)btn{
    if (btn.tag == 1000) {
        //生日
        [self SQ_oneButtonClick];
    } else if (btn.tag == 1001) {
        //地址
        [self SQ_towButtonClick];
    }else if (btn.tag == 1002) {
        //身高
        [self SQ_ShenggaoButtonClick];
    }else if (btn.tag == 1003) {
        //体重
        [self SQ_TizhongButtonClick];
    }
}

-(void)SQ_oneButtonClick{
    WS(weakSelf);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString* selectValue = [NSString SQ_GetoutYear:-30];
    NSString* minDate = [NSString SQ_GetoutYear:-100];
    NSString* maxDate = [NSString SQ_GetoutYear:-18];
    [BRDatePickerView showDatePickerWithMode:BRDatePickerModeYMD title:@"" selectValue:selectValue minDate:[dateFormatter dateFromString:minDate] maxDate:[dateFormatter dateFromString:maxDate] isAutoSelect:YES resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.shengriLabel.text = selectValue;
        weakSelf.shengriLabel.textColor = UIColor.whiteColor;
    } resultRangeBlock:^(NSDate * _Nullable selectStartDate, NSDate * _Nullable selectEndDate, NSString * _Nullable selectValue) {
        
    }];
}

-(void)SQ_towButtonClick{
    WS(weakSelf);
    [[SQCLLocationManager sharedManager]SQ_Location:^(NSDictionary * _Nonnull cityDic) {
        weakSelf.addressLabel.text = [cityDic objectForKey:@"city"];
        weakSelf.addressLabel.textColor = UIColor.whiteColor;
    }];;
//    InfoMapViewController * vc = [[InfoMapViewController alloc]init];
//    vc.modalPresentationStyle = UIModalPresentationFullScreen;
//    [self presentViewController:vc animated:YES completion:nil];
//    WS(weakSelf);
//    [vc setAddressBlock:^(NSString * _Nonnull address) {
//        weakSelf.addressLabel.text = address;
//        weakSelf.addressLabel.textColor = UIColor.whiteColor;
//    }];
}
//身高
-(void)SQ_ShenggaoButtonClick{
    ShengGaoPopView * view = [[ShengGaoPopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 200+FootHeight)];
   
    LSTPopView * pop = [LSTPopView initWithCustomView:view
                                           parentView:self.view
                                             popStyle:LSTPopStyleSmoothFromBottom dismissStyle:LSTDismissStyleSmoothToBottom];
    pop.hemStyle = LSTHemStyleBottom;
    pop.bgAlpha = 0.5;
    [pop pop];
    LSTPopViewWK(pop)
    [pop setBgClickBlock:^{
        [wk_pop dismiss];
    }];
    WS(weakSelf);
    if ([self.shengaoLabel.text isEqualToString:@"待完善"]) {
        self.shengaoLabel.text= @"170CM";
        self.shengaoLabel.textColor = UIColor.whiteColor;
    }
    view.number = self.shengaoLabel.text;
    [view setNumberBlock:^(NSString * _Nonnull number) {
        weakSelf.shengaoLabel.text = number;
        weakSelf.shengaoLabel.textColor = UIColor.whiteColor;
    }];
}
//体重
-(void)SQ_TizhongButtonClick{
    TiZhongPopView * view = [[TiZhongPopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 200+FootHeight)];
   
    LSTPopView * pop = [LSTPopView initWithCustomView:view
                                           parentView:self.view
                                             popStyle:LSTPopStyleSmoothFromBottom dismissStyle:LSTDismissStyleSmoothToBottom];
    pop.hemStyle = LSTHemStyleBottom;
    pop.bgAlpha = 0.5;
    [pop pop];
    LSTPopViewWK(pop)
    [pop setBgClickBlock:^{
        [wk_pop dismiss];
    }];
    WS(weakSelf);
    if ([self.tizhongLabel.text isEqualToString:@"待完善"]) {
        self.tizhongLabel.text = @"60KG";
        self.tizhongLabel.textColor = UIColor.whiteColor;
    }
    view.number  = self.tizhongLabel.text;
    [view setNumberBlock:^(NSString * _Nonnull number) {
        weakSelf.tizhongLabel.text = number;
        weakSelf.tizhongLabel.textColor = UIColor.whiteColor;
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (UILabel *)shengaoLabel{
    if (!_shengaoLabel) {
        _shengaoLabel = [[UILabel alloc]init];
        _shengaoLabel.font = FONT_MEDIUM(14);
        _shengaoLabel.textColor = SQColor(@"#6B6B6B");
        _shengaoLabel.text = @"待完善";
    }
    return _shengaoLabel;
}
- (UILabel *)tizhongLabel{
    if (!_tizhongLabel) {
        _tizhongLabel = [[UILabel alloc]init];
        _tizhongLabel.font = FONT_MEDIUM(14);
        _tizhongLabel.textColor = SQColor(@"#6B6B6B");
        _tizhongLabel.text = @"待完善";
    }
    return _tizhongLabel;
}
- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc]init];
        _addressLabel.font = FONT_MEDIUM(14);
        _addressLabel.textColor = SQColor(@"#6B6B6B");
        _addressLabel.text = SQNSLocalString(@"待完善");
    }
    return _addressLabel;
}
- (UILabel *)shengriLabel{
    if (!_shengriLabel) {
        _shengriLabel = [[UILabel alloc]init];
        _shengriLabel.font = FONT_MEDIUM(14);
        _shengriLabel.textColor = SQColor(@"#6B6B6B");
        _shengriLabel.text = SQNSLocalString(@"待完善");
    }
    return _shengriLabel;
}

- (UITextField *)textField{
    if (!_textField) {
        _textField = [[UITextField alloc]init];
        _textField.backgroundColor = SQColor(@"#E4E4E4");
        _textField.textColor = UIColor.blackColor;
        _textField.font = FONT_MEDIUM(17);
        _textField.delegate = self;
        _textField.placeholder = SQNSLocalString(@"填写微信号~");
        [_textField setValue:SQColor(@"#6B6B6B") forKeyPath:@"placeholderLabel.textColor"];
//        _textField.returnKeyType = UIReturnKeyDone;
        _textField.layer.masksToBounds = YES;
        _textField.layer.cornerRadius = 8;
        _textField.textAlignment = NSTextAlignmentCenter;
        
    }
    return _textField;
}
@end
